package com.vonchenchen.android_renderer;

import android.app.Activity;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.vonchenchen.process.RendererClient;

/**
 * Created by lidede on 2021/6/29.
 */
public class RemoteRendererActivity extends Activity {

    private SurfaceView mMainSurfaceView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_remote_renderer);

        mMainSurfaceView = findViewById(R.id.sv_main);

        mMainSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
            @Override
            public void surfaceCreated(@NonNull SurfaceHolder holder) {

                //RendererClient.getInstance().initSurface(holder.getSurface());
            }

            @Override
            public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) {

            }

            @Override
            public void surfaceDestroyed(@NonNull SurfaceHolder holder) {

            }
        });

        RendererClient.getInstance().connect(this, new RendererClient.OnConnectListener() {
            @Override
            public void OnConnected() {
                if(mMainSurfaceView.getHolder().getSurface().isValid()){
                    RendererClient.getInstance().initSurface(mMainSurfaceView.getHolder().getSurface());
                }
            }

            @Override
            public void OnDisConnect() {

            }
        });
    }
}
